<?php

namespace Common\Model;

use Think\Model;

class OrderGoodsModel extends Model {
	
    /**
     *  获取单个订单
     */
	public function getOrderGoods($id = null, $where = array()) {
        if (!empty($id)) {
            $where['orderID'] = $id;
        }

        $result = $this->where($where)->find();

        return $result;
    }

    /**
     * 获得列表（带基本查询）
     */
    public function getOrderGoodsList($pageNo = 1, $pageSize = 15, $where = array(), $order = array()) {
        $rt = $this->where($where)->page("$pageNo,$pageSize")->order($order)->select();
        return $rt;
    }

    public function getOrderGoodsListLength($where = array()) {
        return $this->where($where)->count();
    }

    /**
     * 添加单个信息
     * @return type
     */
    public function addOrderGoods($data = '') {
        $rt = false;
        if ($this->create($data)) {
            $rt = $this->add();
        }
        return $rt;
    }

    /**
     * 更新信息(注意$data一定要有主键id,若$data为空，则默认是对$_POST数组处理)
     * @return type
     */
    public function updateOrderGoods($data = '') {
        $rt = false;
        if ($this->create($data)) {
            $rt = $this->save();
        }
        return $rt;
    }

    /**
     * 删除
     */
    public function deleteOrderGoods($id) {
        if ($id <= 0) {
            $this->error = "无效ID";
            return false;
        }
        $data = array("isOn" => 0, "updateTime" => time());
        return $this->where("OrderID=$id")->save($data);
    }

    

}
